﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PlayDeezGames.Common;
using ASCII.Common;
using System.Windows.Threading;

namespace ASCII.ClickTheYellowBox
{
    public abstract class CTYBStateBase : State<CTYBState>
    {
        private ASCIIRenderer renderer;
        protected ASCIIRenderer Renderer
        {
            get
            {
                return renderer;
            }
        }
        private CTYBStateBase() { }
        public CTYBStateBase(ASCIIRenderer theRenderer)
        {
            renderer = theRenderer;
        }
    }
    public class CTYBSplashState:CTYBStateBase
    {
        private DispatcherTimer timer;

        private void OnTimer(object sender, EventArgs e)
        {
            ExitState = CTYBState.Title;
            Finish();
            Parent.OnMessage(new MessageBase(StateMachine<CTYBState>.MSGID_Step));
        }

        public CTYBSplashState(ASCIIRenderer theRenderer):base(theRenderer)
        {           
            timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 3);
            timer.Tick += OnTimer;
        }

        protected override void OnStart()
        {
            timer.Start();
            Renderer.SetCells(0, 0, Renderer.GridBoard.Columns, Renderer.GridBoard.Rows, 0, ASCIICellColor.Black, ASCIICellColor.Black);
            Renderer.DrawTable(TableDrawingPalette.V2H2Palette, new int[] { 0, Renderer.GridBoard.Columns - 1 }, new int[] { 0, Renderer.GridBoard.Rows - 1 }, ASCIICellColor.Blue, ASCIICellColor.DarkGray, false);
            Renderer.WriteText(5, 14, "a production of PlayDeez Games", ASCIICellColor.Cyan, ASCIICellColor.Black);
        }

        protected override void OnIdle()
        {
        }

        protected override void OnFinish()
        {
            timer.Stop();
        }

        public override bool OnMessage(MessageBase theMessage)
        {
            if (theMessage.MessageId == CTYBStateMachine.MSGID_MouseUp)
            {
                ExitState = CTYBState.Title;
                Finish();
                return true;
            }
            else if (theMessage.MessageId == CTYBStateMachine.MSGID_Draw)
            {
                Renderer.Render();
                return true;
            }
            else
            {
                return base.OnMessage(theMessage);
            }
        }
    }
}
